import java.lang.reflect.Array;
import java.util.Arrays;

public class StringDemo {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(args));
        double x = 100.124124;
//        String.format()
        String xStr = String.valueOf(x);
        //从字符串类型转换为基本数据类型
        //需要调用原始类型对应的包装类上的parse方法
        double xx = Double.parseDouble(xStr);
        double y = xx + 100.1;
        int xy = 100;

        //自动转换：调用了double的包装器类上的toString方法
        String output = "最终金额为：" + Double.toString(x);
        String xyStr = String.valueOf(xy);
//        String origin = "北国风光，千里冰封，万里雪飘。望长城内外，惟余莽莽；大河上下，顿失滔滔。(余 通：馀)山舞银蛇，原驰蜡象，欲与天公试比高。(原驰 一作：原驱)须晴日，看红装素裹，分外妖娆。江山如此多娇，引无数英雄竞折腰。惜秦皇汉武，略输文采；唐宗宋祖，稍逊风骚。一代天骄，成吉思汗，只识弯弓射大雕。俱往矣，数风流人物，还看今朝。";
//        StringBuilder s = new StringBuilder();
//        StringBuffer st = new StringBuffer();
//
//        for (int i = 0; i < origin.length();i++) {
//            st.append(origin.charAt(i));
//            System.out.println(System.identityHashCode(st));
//        }
//
//        st.insert(10, "test");
//
//        System.out.println(st);
    }

    public static void strBuilderDemo() {
        String origin = "北国风光，千里冰封，万里雪飘。望长城内外，惟余莽莽；大河上下，顿失滔滔。(余 通：馀)山舞银蛇，原驰蜡象，欲与天公试比高。(原驰 一作：原驱)须晴日，看红装素裹，分外妖娆。江山如此多娇，引无数英雄竞折腰。惜秦皇汉武，略输文采；唐宗宋祖，稍逊风骚。一代天骄，成吉思汗，只识弯弓射大雕。俱往矣，数风流人物，还看今朝。";
        int size = 5;
        char[] output = new char[size];
        for (int i = 0; i < origin.length();i++) {
            output[i] = origin.charAt(i);
            if (i >= size - 1) {
                System.out.println("执行扩容");
                char[] tmp = new char[size * 2];
                System.arraycopy(output, 0 , tmp, 0, size);
                size = size * 2;
                output = tmp;
            }
        }

        System.out.println(Arrays.toString(output));
    }

    public static void strConcat() {
        String output = "";
        System.out.println(System.identityHashCode(output));
        output += "hello";
        System.out.println(System.identityHashCode(output));
    }

    public static void baseDemo() {
        String strA = "hello world!";
        String strB = new String("hello world!");
        String strC = "hello world!";
        String strD = new String("hello world!");
        System.out.println(strA ==  strB);
        System.out.println(strA ==  strC);
        System.out.println(strB ==  strD);

        System.out.println("=====");
        System.out.println(System.identityHashCode(strA));
        System.out.println(System.identityHashCode(strB));
        System.out.println(System.identityHashCode(strC));
        System.out.println(System.identityHashCode(strD));
        System.out.println(strA.equals(strB));

        System.out.println("+++++++++++");
        System.out.println(strA.length());
        System.out.println(Arrays.toString(strA.getBytes()));
        System.out.println(strA.toUpperCase());
        System.out.println(strA.charAt(3));
        System.out.println(strA.contains("中国"));
        System.out.println(strA.indexOf("l"));

        //intern是获取字符串在字符串池中的引用
        System.out.println(strB.intern() == strA);


    }
}
